/*
 *
 * User: Administrator
 * Date: 2011-4-14
 * Time: 16:17
 *
 *
 */
using System;
using System.Collections;

namespace shellsort
{
	/// <summary>
	/// Description of shellsort.
	/// </summary>
	public class shellsort
	{
		public shellsort()
		{

		}
		
		public void ShellSort(int[] arr,int numElements)
		{
			int inner=0, temp;
			int h = 1;
			
			while (h <numElements/3)
				h = h * 3 + 1;
			
			Console.WriteLine("h= "+h);
			
			while (h > 0)
			{
				
				for (int outer = h; outer <numElements;outer++)
				{
					temp = arr[outer];
					inner = outer;
					while ((inner > h - 1) && arr[inner-h] >= temp)
					{
						arr[inner] = arr[inner-h];
						inner -= h;
					//	Console.WriteLine(arr[inner]);
					}
					arr[inner] = temp;	
						// Console.WriteLine(arr[inner]);
				}
			
				h = (h - 1) / 3;
			}
			
			for(int index = 0; index < numElements; index++)	Console.Write(arr[index]+"/");
		}
		
	}
}
